package com.zmn.mcc.permit.mysql.annotation.model;

import com.zmn.mcc.permit.mysql.annotation.ZmnDPermitConfig;
import com.zmn.mcc.permit.mysql.annotation.ZmnDPermitType;
import com.zmn.mcc.permit.mysql.enums.DPermitTypeEnum;

/**
 * @author duanzuocai
 * @version v1.0
 * @since 2020/7/4 16:46
 */
public class ZmnDPermitConfigModel {

    private String clazz;
    private String method;
    private ZmnDPermitConfig annotation;

    public ZmnDPermitConfigModel(String clazz, String method, ZmnDPermitConfig annotation) {
        this.clazz = clazz;
        this.method = method;
        this.annotation = annotation;
    }

    public String getColumnByType(int type) {
        ZmnDPermitType[] mapping = annotation.mapping();

        for (ZmnDPermitType type2 : mapping) {
            if (type2.type().getDPermitType() == type) {
                return type2.column();
            }
        }

        return DPermitTypeEnum.getColumnByType(type);
    }

    public String getColumnSubqueriesByType(int type) {
        ZmnDPermitType[] mapping = annotation.mapping();

        for (ZmnDPermitType type2 : mapping) {
            if (type2.type().getDPermitType() == type) {
                return type2.subqueries();
            }
        }

        return null;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public ZmnDPermitConfig getAnnotation() {
        return annotation;
    }

    public void setAnnotation(ZmnDPermitConfig annotation) {
        this.annotation = annotation;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    @Override
    public String toString() {
        return new StringBuilder(clazz == null ? "" : clazz).append("#").append(method == null ? "" : method).toString();
    }
}
